package com.rui.service.impl;

import com.rui.domain.Job;
import com.rui.domain.JobVO;
import com.rui.domain.StringIntDTO;
import com.rui.mapper.JobMapper;
import com.rui.mapper.MyCustomMapper;
import com.rui.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("jobService")
public class JobServiceImpl implements JobService {

    @Autowired
    private JobMapper jobMapper;
    @Autowired
    private MyCustomMapper myCustomMapper;

    @Override
    public boolean insertJob(Job job) {
        int row = jobMapper.insert(job);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<JobVO> findJobByStudentNumber(String studentNumber) {
        List<JobVO> jobVOList = myCustomMapper.findJobByStuNo(studentNumber);
        if (jobVOList != null && jobVOList.size() > 0) {
            return jobVOList;
        }
        return null;
    }

    @Override
    public boolean updateJobById(Job job) {
        int row = jobMapper.updateByPrimaryKey(job);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteJobById(String id) {
        int row = jobMapper.deleteByPrimaryKey(id);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<JobVO> findStudentJobByJobNo(String jobNo,int year) {
        StringIntDTO dto = new StringIntDTO(jobNo, year);
        return myCustomMapper.findJobByJobNo(dto);
    }


    @Override
    public List<JobVO> findAll(String grade) {
        return myCustomMapper.findAllJob(grade);
    }
}

